#include "stdafx.h"
#include "Commons.h"
#include <stdlib.h>
#include <stdio.h>

#ifdef WIN32
#include <crtdbg.h>
#endif

#if defined(TARGET_IPHONE_SIMULATOR) || defined(TARGET_OS_IPHONE)
#	include <sys/time.h>
#else //WIN32
#	include <windows.h>
#	include <Mmsystem.h>
#endif

extern "C" int S_GetTime (void)
{
#if defined(TARGET_IPHONE_SIMULATOR) || defined(TARGET_OS_IPHONE)
    struct timeval	tp;
    gettimeofday(&tp, 0);
	static long old_tv_sec_1 = tp.tv_sec;
    return ((tp.tv_sec - old_tv_sec_1) * 1000 + tp.tv_usec / 1000);
#else // WIN32
	return timeGetTime();
#endif
}

extern "C" int S_GetTimeMicros (void)
{
#if defined(TARGET_IPHONE_SIMULATOR) || defined(TARGET_OS_IPHONE)
    struct timeval	tp;
    gettimeofday(&tp, 0);

	static long old_tv_sec_2 = tp.tv_sec;
    return ((tp.tv_sec - old_tv_sec_2) * 1000000 + tp.tv_usec);
#else // WIN32
	return timeGetTime() * 1000;
#endif
}


void debug_out(const char* fmt, ...)
{
#ifdef WIN32
	char str[1024];
	va_list arg_list;

	va_start(arg_list, fmt);
	vsprintf_s(str, fmt, arg_list);

	OutputDebugStringA(str);
	OutputDebugStringA("\n");
#endif
}
